﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_IDAL;
using Zor_Modes;

namespace Zor_DAL
{
    public class AppUsers_DAL
    {
        /// <summary>
        /// 添加App用户
        /// </summary>
        /// <param name="aus"></param>
        /// <returns></returns>
        public static BaseAnswer InserAppUsers(AppUsers aus)
        {
            var sql = "insert into AppUsers values(@AppUser_LoginName,@AppUser_LoginPassword,@AppUser_RealName,@AppUser_IdCardNo,@AppUser_LoginTime,@AppUser_State)";
            BaseAnswer bar = DapperInsert<AppUsers>.DoInsert(sql, aus);
            return bar;
        }

        /// <summary>
        /// 判断用户是否已注册过(身份证或者手机号)
        /// </summary>
        /// <param name="aus"></param>
        /// <returns></returns>
        public static AppUsers GetAppUsersByLoginName(AppUsers aus)
        {
            var sql = "";
            if (!string.IsNullOrEmpty(aus.AppUser_LoginName))
            {
                sql = "select * from AppUsers where AppUser_LoginName = @AppUser_LoginName";
            }
            if (!string.IsNullOrEmpty(aus.AppUser_IdCardNo))
            {
                sql = "select * from AppUsers where AppUser_IdCardNo = @AppUser_IdCardNo";
            }
            return DapperQuery<AppUsers>.DoQueryT(sql, aus);
        }

        /// <summary>
        /// App用户登录
        /// </summary>
        /// <param name="us"></param>
        /// <returns></returns>
        public static AppUsers GetAppUserByLoginNameAndPass(AppUsers us)
        {
            var sql = "select * from AppUsers where AppUser_LoginName=@AppUser_LoginName and AppUser_LoginPassword=@AppUser_LoginPassword";
            return DapperQuery<AppUsers>.DoQueryT(sql, us);
        }


        public static BaseAnswer UpdateAppUsersPassword(AppUsers us)
        {
            var sq1 = "update AppUsers set AppUser_LoginPassword=@AppUser_LoginPassword where AppUser_Id=@AppUser_Id";
            BaseAnswer bar = DapperEdit<AppUsers>.DoEdit(sq1, us);
            return bar;
        }

    }
}
